import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/education/couser_center/textbook_list_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/education/teacher_power/lecturer_list_page_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/get_new_dict_all_entity.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';
import 'package:get/get.dart';

///主题
class IntegratedThemeController extends GetxController {
  /// 讲师名字列表
  List<LecturerListPageEntity> lecturerList = [];

  /// 选择的人员
  int? selectPerson;

  Future<List<TextbookListEntity>> textbookList(int index, int size, GetNewDictAllEntity getNewDictAllEntity, {String? search}) async {
    final res = await HttpUtil().generateGetRequest<List<TextbookListEntity>>(
      Interface.textbookList,
      queryParameters: {
        'pageNum': index,
        'pageSize': size,
        'type': 0, //课程类型 0：全部 1：我的任务课程
        'textbookName': getNewDictAllEntity.searchX.value, //课程名称
        'textbookLecturerId': getNewDictAllEntity.workKindBack2, //	讲师ID
        'textbookTypeDicId': getNewDictAllEntity.id, //	课程类型ID
        'startDate': getNewDictAllEntity.startDate, //开始时间
        'endDate': getNewDictAllEntity.endDate, //结束时间
      },
    ).execute();
    List<TextbookListEntity>? list = [];
    res.onSuccess((result) {
      if (result.data != null) {
        list = result.data;
      }
    });
    return list!;
  }

  ///点击进入课程详情
  void courseDetail(TextbookListEntity item) {
    //条目课程id  讲师id（需要 查询讲师详情/education//lecturer/detail）
    Get.toNamed(AppRoutes.courseDetailPage, arguments: {
      'id': item.id,
      'textbookLecturerId': item.textbookLecturerId,
      //isDirectory && isQuestion 都为0时（不进入学习 false）
      'isStudy': item.isDirectory == 0 ? false : true,
    });
  }

  @override
  void onInit() {
    super.onInit();
    //获取教师姓名
    listPage();
  }

  void listPage() async {
    final res = await HttpUtil().generateGetRequest<List<LecturerListPageEntity>>(
      Interface.listPage,
      queryParameters: {
        'pageNum': 1,
        'pageSize': 1000,
      },
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        lecturerList = result.data!;
      }
    });
  }
}
